/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.brainstretch.ejb.managers;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.*;
import org.brainstretch.models.User;

/**
 *
 * @author mrodaitis
 */
@Stateless
@LocalBean
public class UserSessionManager {
    
    @PersistenceUnit
    EntityManagerFactory entityManagerFactory;

    public User findUserByName(String username){
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Query findUser = entityManager.createQuery("SELECT user FROM User user WHERE user.name = ?1").setParameter(1, username);
        User found = null;
        try{
            found = (User)findUser.getSingleResult();
        }
        catch(NoResultException ex){
            //TODO determine what to do from here.
        }
        return found;
    }
    
}
